package tcp;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        DataOutputStream dataOutputStream = null;
        try {
            //获取一个Socket端点对象
            socket = new Socket("127.0.0.1", 9999);

            //通过端点对象获取一个低级的输出流对象
            OutputStream outputStream = socket.getOutputStream();
            //包装成高级输出流
            dataOutputStream = new DataOutputStream(outputStream);

            //使用流对服务端发送数据
            dataOutputStream.writeUTF("你好啊!!!");
        }catch (Exception ignored){

        }finally {
            //关闭流
            try{
                if (socket != null) {
                    socket.close();
                }
                if (dataOutputStream != null) {
                    dataOutputStream.close();
                }
            }catch (Exception ignored){

            }
        }
    }
}
